﻿<UserControl x:Class="MVVM.Demo.SearchCustomersView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MVVM.Demo"
    Height="Auto" Width="Auto">

    <UserControl.Resources>

        <!-- CustomerDataTemplate -->
        <DataTemplate x:Key="PropertyInfoTemplate">
            <TextBlock  Text="{Binding Path=Name}" Foreground="Black" 
                        TextTrimming="CharacterEllipsis"
                        VerticalAlignment="Center"/>
        </DataTemplate>

        <!-- CustomerDataTemplate -->
        <DataTemplate x:Key="ConditionTemplate">
            <TextBlock  Text="{Binding}" Foreground="Black" 
                        TextTrimming="CharacterEllipsis"
                        VerticalAlignment="Center"/>
        </DataTemplate>


        <!-- toolButton -->
        <ControlTemplate x:Key="toolButton" TargetType="{x:Type Button}">
            <Grid Background="Transparent" Width="35" Height="35">

                <Ellipse x:Name="ell" 
                         Stroke="White" 
                         Fill="White"
                         HorizontalAlignment="Center" 
                         VerticalAlignment="Center"
                         Width="35" Height="35"
                         Margin="0" StrokeThickness="3" >
                </Ellipse>

                <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent},
                 Path=(local:ButtonProps.ImageUrl)}" HorizontalAlignment="Center" 
                 VerticalAlignment="Center"
                 Stretch="Fill" Width="20" Height="20"
                 Margin="0" />

            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter TargetName="ell" Property="Stroke" Value="Black"/>
                    <Setter TargetName="ell" Property="BitmapEffect">
                        <Setter.Value>
                            <OuterGlowBitmapEffect GlowColor="Black" GlowSize="10"/>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>



    </UserControl.Resources>


    <DockPanel LastChildFill="True" Background="White">

        <Grid DockPanel.Dock="Top">
            <Grid.RowDefinitions>
                <RowDefinition Height="60"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>


            <Grid Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
              Background="Black">

                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="2"/>
                </Grid.RowDefinitions>

                <StackPanel Margin="10,0,0,0" Orientation="Horizontal" VerticalAlignment="Stretch">
                    <Image Source="../Images/Customers.png" HorizontalAlignment="Left" 
                       VerticalAlignment="Center" Width="36" Height="36"/>


                    <Label Content="{Binding DisplayName}" FontWeight="Bold" Foreground="Orange" 
                       FontSize="18" HorizontalAlignment="Left" VerticalAlignment="Center"/>


                </StackPanel>

                <Rectangle Grid.Row="1" HorizontalAlignment="Stretch" Height="2" Fill="Black" 
                           VerticalAlignment="Bottom"/>


            </Grid>

            <StackPanel Orientation="Horizontal" Grid.Row="1" Height="60">

                <Label Content="Pick Property" Foreground="Black" FontWeight="Bold" Margin="10" 
                    VerticalAlignment="Center"/>
                
                <ComboBox x:Name="cmbProperty"  Width="100"
                    VerticalContentAlignment="Center"
                    IsSynchronizedWithCurrentItem="True"
                    Height="23" ItemsSource="{Binding Path=AvailableProperties}"
                    ItemTemplate="{StaticResource PropertyInfoTemplate}"/>


                <Label Content="Pick Condition" Foreground="Black" FontWeight="Bold" Margin="10" 
                    VerticalAlignment="Center"/>
                <ComboBox x:Name="cmbCondition"  Width="100"
                    VerticalContentAlignment="Center"
                    IsSynchronizedWithCurrentItem="True"
                    Height="23" ItemsSource="{Binding Path=AvailableConditions}" 
                    ItemTemplate="{StaticResource ConditionTemplate}"/>


                <Label Content="Pick Value" Foreground="Black" FontWeight="Bold" Margin="10" 
                    VerticalAlignment="Center"/>
                <TextBox x:Name="txtValue" Width="150" Height="23" MaxLength="9" UndoLimit="1" 
                    VerticalAlignment="Center"  VerticalContentAlignment="Center"
                    Style="{StaticResource ValidatingTextBox}"
                    Text="{Binding Path=CurrentFilterText}"/>

                <Button Content="Run Search" 
                    Margin="10"
                    Template="{StaticResource toolButton}" 
                    local:ButtonProps.ImageUrl="../Images/go.png"
                    ToolTip="Run Search"
                    VerticalAlignment="Center"
                    Command="{Binding DoSearchCommand}"/>

            </StackPanel>

        </Grid>

        <Grid Margin="0" Background="White">
            
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <Label Grid.Row="0" FontWeight="Bold" Margin="10,0,0,0" 
                   Content="Search customers results"/>

            <ListView Grid.Row="1" Margin="0" 
                  ScrollViewer.VerticalScrollBarVisibility="Auto"
                  ScrollViewer.HorizontalScrollBarVisibility="Visible"
                  SelectionMode="Single" 
                  local:SortableListBehaviour.IsGridSortable="True"
                  ItemsSource="{Binding MatchedCustomers}"
                  ItemContainerStyle="{StaticResource ListViewContainer}"
                  IsSynchronizedWithCurrentItem="True"
                  Background="Transparent" 
                  BorderBrush="#FFFFFBFB" 
                  Foreground="#FFB5B5B5" 
                  Opacity="1" 
                  BorderThickness="2" 
                  HorizontalAlignment="Stretch" 
                  VerticalAlignment="Stretch" 
                  Width="Auto" Height="Auto">
                <ListView.View>
                    <GridView  
                            ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle}">
                        <GridViewColumn Header="CustomerId" Width="100" 
                                    DisplayMemberBinding="{Binding Path=CustomerId.DataValue}"/>
                        <GridViewColumn Header="FirstName" Width="100" 
                                    DisplayMemberBinding="{Binding Path=FirstName.DataValue}"/>
                        <GridViewColumn Header="LastName" Width="100" 
                                    DisplayMemberBinding="{Binding Path=LastName.DataValue}"/>
                        <GridViewColumn Header="Email" Width="100" 
                                    DisplayMemberBinding="{Binding Path=Email.DataValue}"/>
                        <GridViewColumn Header="HomePhoneNumber" Width="150" 
                                    DisplayMemberBinding="{Binding Path=HomePhoneNumber.DataValue}"/>
                        <GridViewColumn Header="MobilePhoneNumber" Width="150" 
                                    DisplayMemberBinding="{Binding Path=MobilePhoneNumber.DataValue}"/>
                        <GridViewColumn Header="Address1" Width="100" 
                                    DisplayMemberBinding="{Binding Path=Address1.DataValue}"/>
                        <GridViewColumn Header="Address2" Width="100" 
                                    DisplayMemberBinding="{Binding Path=Address2.DataValue}"/>
                        <GridViewColumn Header="Address3" Width="100" 
                                    DisplayMemberBinding="{Binding Path=Address3.DataValue}"/>

                    </GridView>
                </ListView.View>
                
                <ListView.ContextMenu>
                    <ContextMenu x:Name="menu" Margin="0,0,0,0" Height="Auto" Foreground="White"
                          ItemContainerStyle="{StaticResource ContextMenuItemStyle}"
                          ItemsSource="{Binding SearchMenuOptions}"
                          VerticalAlignment="Top">
                    </ContextMenu>
                </ListView.ContextMenu>
                
            </ListView>
        </Grid>
        
    </DockPanel>
</UserControl>
